﻿using Dm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using zjxj_repair.Utils;

namespace zjxj_repair.Bean.Model
{
    public class SoketSendList
    {
        private static readonly object _lock = new object();

        private static List<string> sendDicInit;

        static SoketSendList()
        {
            sendDicInit = new List<string>();
        }

        public static List<string> SendList
        {
            get
            {
                lock (_lock)
                {
                    return sendDicInit;
                }
            }
        }

        public static void AddData(string data)
        {
            lock (_lock)
            {
                if (!sendDicInit.Contains(data))
                {
                    sendDicInit.Add(data);

                    Tools.ProduceLogText($"[缓存操作]-缓存指令，当前缓存池剩余[{sendDicInit.Count}]");
                }
            }
        }

        public static void RemoveData(string data)
        {
            lock (_lock)
            {
                if (sendDicInit.Contains(data))
                {
                    sendDicInit.Remove(data);

                    Tools.ProduceLogText($"[缓存操作]-消费指令，当前缓存池剩余[{sendDicInit.Count}]");
                }
            }
        }

        internal static (bool, string) IsContains(string data)
        {
            lock (_lock)
            {
                foreach (var item in sendDicInit)
                {
                    if (item.Contains(data))
                    {
                        return (true, item);
                    }
                }

                return (false, "");
            }
        }
    }
}
